package com.arcticcoding.telemetrie;

import java.util.Observable;
import java.util.Observer;

import android.location.Location;
import android.util.Log;

import com.arcticcoding.telemetrie.comm.CameraResponse;
import com.arcticcoding.telemetrie.comm.GPSResponse;
import com.arcticcoding.telemetrie.comm.TelemetrieResponse;

/**
 * 
 * @author steffenschuhmann
 * @version 0.01 
 */
public abstract class TelemetrieCallback implements Observer {
	private static final String TAG = "com.arcticcoding.telemetrie.TelemetrieCallback";
	
	public TelemetrieCallback() {
		
	}
	
	/**
	 * Is called when a sensor value has changed. 
	 * 
	 */
	protected void valueHasChanged(TelemetrieResponse value) {
		if(value instanceof CameraResponse) {
			cameraServiceValueHasChanged((byte[])value.payload);
		} else if(value instanceof GPSResponse) {
			com.arcticcoding.dto.Location location;
			location = new com.arcticcoding.dto.Location((Location)value.payload);
			geoServiceValueHasChanged(location);
		} else {
			Log.d(TAG, "Unknown TelemetrieValue received: " + value.toString());
		}
	}
	
	@Override
	public void update(Observable observable, Object data) {
		if(data instanceof TelemetrieResponse) {
			valueHasChanged((TelemetrieResponse)data);
		} else {
			Log.d(TAG, "Unknown value type: " + data.toString());
		}
	}
	
	public abstract void geoServiceValueHasChanged(com.arcticcoding.dto.Location newLocation);
	
	public abstract void cameraServiceValueHasChanged(byte[] imageData);
}
